<?php
namespace Kuoqi\Html\Kuoqiui;
/**
 * 专属后台模板库，配合权限模块的相关信息，是html片段的良好导体
 * Class AHtml
 * @package App\Admin\Template
 */
class Form{

    /**
     * TeApihtml
     * createby kuoqi at 2022/11/8 10:46
     * @param $title
     * @param $name
     * @param string $defval
     * @param string $apiurl
     * @return string
     */
    static public function Apihtml($title,$name,$defval = '',$apiurl = '',$apifuncname = ''){
        return sprintf('<div class="row-flex mgt-15 text-ch">
                    <div class="col-auto text-c">
                        <span class="label wdr-4 label-small">%s</span>
                    </div>
                    <div class="col-auto text-c"><span class="label label-small">:</span></div>
                    <div class="col-other">
                        <input type="apihtml" 
                        data-url="%s" 
                        name="data[%s]" 
                        value="%s" class="form-input" 
                        onbtnclick="%s" />
                    </div>
                </div>'
            ,$title
            ,$apiurl
            ,$name
            ,$defval
            ,$apifuncname
        );
    }


    /**
     * 常规text文本的书写
     * @param $title 显示字段名称
     * @param $name 字段的键名
     * @param string $defval 字段的键值
     * @param string $desc 字段描述
     * @return string
     */
    static public function Text($title,$name,$defval = '',$desc = ''){
        return sprintf('<div class="row-flex mgt-15 text-ch">
                    <div class="col-auto text-c">
                        <span class="label wdr-4 label-small">%s</span>
                    </div>
                    <div class="col-auto text-c"><span class="label label-small">:</span></div>
                    <div class="col-other">
                        <input name="data[%s]" value="%s" class="form-input" placeholder="%s" />
                    </div>
                </div>'
            ,$title
            ,$name
            ,$defval
            ,$desc
        );
    }

    /**
     * 用户修改密码框
     * @param $title
     * @param $name
     * @param string $desc
     * @return string
     */
    static public function Password($title,$name,$desc = ''){
        return sprintf('<div class="row-flex mgt-15 text-ch">
                    <div class="col-auto text-c">
                        <span class="label wdr-4 label-small">%s</span>
                    </div>
                    <div class="col-auto text-c"><span class="label label-small">:</span></div>
                    <div class="col-other">
                        <input type="password" name="data[%s]" value="" class="form-input" placeholder="%s" />
                    </div>
                </div>'
            ,$title
            ,$name
            ,$desc
        );
    }

    /**
     * radio模块的使用
     * @param $title
     * @param $name
     * @param string $defval
     * @param array $list
     * @return string
     */
    static public function Radio($title,$name,$defval = '',$list = array()){
        $ipts = '';
        foreach ($list as $item){
            $ipts .= sprintf('<input name="data[%s]" type="radio" value="%s" placeholder="%s" data-value="%s" />'
                ,$name
                ,$item['value']
                ,$item['name']
                ,$defval
                );
        }
        return sprintf('<div class="row-flex mgt-15 text-ch">
                            <div class="col-auto text-c">
                                <span class="label wdr-4 label-small">%s</span>
                            </div>
                            <div class="col-auto text-c"><span class="label label-small">:</span></div>
                            <div class="col-other">
                                %s
                            </div>
                        </div>'
            ,$title
            ,$ipts
        );
    }

    //选择框
    static public function Select($title,$name,$defval = '',$apiurl = ''){
        return sprintf('<div class="row-flex mgt-15 text-ch">
                            <div class="col-auto text-c">
                                <span class="label wdr-4 label-small">%s</span>
                            </div>
                            <div class="col-auto text-c"><span class="label label-small">:</span></div>
                            <div class="col-other">
                                <select class="form-select" type="api" name="data[%s]" data-url="%s" data-value="%s">==请选择==</select>
                            </div>
                        </div>'
            ,$title
            ,$name
            ,$apiurl
            ,$defval
        );
    }

    /**
     * textarea
     * @param $title
     * @param $name
     * @param string $defval
     * @param string $desc
     * @return string
     */
    static public function Textarea($title,$name,$defval = '',$desc = '',$rowcol = 6){
        return sprintf('<div class="row-flex mgt-15 text-ch">
                            <div class="col-auto text-c">
                                <span class="label wdr-4 label-small">%s</span>
                            </div>
                            <div class="col-auto text-c"><span class="label label-small">:</span></div>
                            <div class="col-other">
                                <textarea name="data[%s]" rows="%s" class="form-textarea" placeholder="%s" >%s</textarea>
                            </div>
                        </div>'
            ,$title
            ,$name
            ,$rowcol
            ,$desc
            ,$defval
        );
    }
    //marked的文档部分的标签
    static public function TextMarked($title,$name,$defval = ''){
        return sprintf('<div class="row-flex mgt-15 text-ch">
                            <div class="col-auto text-c">
                                <span class="label wdr-4 label-small">%s</span>
                            </div>
                            <div class="col-auto text-c"><span class="label label-small">:</span></div>
                            <div class="col-other">
                                <textarea name="data[%s]" type="editor" data-name="data[%s-editor]">%s</textarea>
                            </div>
                        </div>'
            ,$title
            ,$name
            ,$name
            ,$defval
        );
    }

    /**
     * 图片模块的相关展示
     * @param $title
     * @param $name
     * @param string $defval
     * @return string
     */
    static public function Image($title,$name,$defval = '',$url = ''){
        return sprintf('<div class="row-flex mgt-15 text-ch">
                            <div class="col-auto text-c">
                                <span class="label wdr-4 label-small">%s</span>
                            </div>
                            <div class="col-auto text-c"><span class="label label-small">:</span></div>
                            <div class="col-other">
                                <input type="image" name="data[%s]" value="%s" data-url="%s" class="form-input"  />
                            </div>
                        </div>'
            ,$title
            ,$name
            ,$defval
            ,$url
        );
    }

}